package View;

import javax.swing.*;
import java.awt.Color;
import javax.swing.GroupLayout.Alignment;
import javax.swing.LayoutStyle.ComponentPlacement;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import Model.*;
import Controller.*;

public class ConsultarPessoa extends JPanel {

	static JPanel consultar;
	static JButton consulte;
	JLabel p, d;
	static JFormattedTextField paciente, dentista;
	static Long pcpf, dcpf;
	static boolean pessoa = false;

	public static void getPessoa(Pessoa p){
		if (p.tipo.equals("PACIENTE")){
		paciente.setText(p.nome);
		pcpf = p.cpf;
		}else if (p.tipo.equals("DENTISTA")){
			dentista.setText(p.nome);
			dcpf = p.cpf;
		}
	}
	
	public ConsultarPessoa() {
		Pessoa pac = new Pessoa();
		
		consultar = new JPanel();
		consultar.setBackground(null);
		//consultar.setBorder(BorderFactory.createTitledBorder("CONSULTAR PESSOA"));
		consulte = new JButton("");
		consulte.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				TelaPessoa.abrirPesquisaPessoa();
				consulte.setEnabled( false ); 

			}
		});
		consulte.setBackground(new Color(255, 255, 255));
		consulte.setIcon(new ImageIcon(ConsultarPessoa.class.getResource("/Clinica/imagens/m_pessoa.png")));
		
		p = new JLabel("PACIENTE");
		p.setHorizontalAlignment(SwingConstants.RIGHT);
		
		d = new JLabel("DENTISTA");
		d.setHorizontalAlignment(SwingConstants.RIGHT);
		
		paciente = new JFormattedTextField();
		
		dentista = new JFormattedTextField();

		paciente.setEnabled( false ); 
		dentista.setEnabled( false ); 
		GroupLayout gl_consultar = new GroupLayout(consultar);
		gl_consultar.setHorizontalGroup(
			gl_consultar.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_consultar.createSequentialGroup()
					.addContainerGap()
					.addGroup(gl_consultar.createParallelGroup(Alignment.LEADING, false)
						.addComponent(d, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
						.addComponent(p, GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE))
					.addPreferredGap(ComponentPlacement.RELATED)
					.addGroup(gl_consultar.createParallelGroup(Alignment.LEADING, false)
						.addComponent(dentista)
						.addComponent(paciente, GroupLayout.DEFAULT_SIZE, 185, Short.MAX_VALUE))
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(consulte, GroupLayout.PREFERRED_SIZE, 73, GroupLayout.PREFERRED_SIZE)
					.addContainerGap())
		);
		gl_consultar.setVerticalGroup(
			gl_consultar.createParallelGroup(Alignment.TRAILING)
				.addGroup(gl_consultar.createSequentialGroup()
					.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
					.addGroup(gl_consultar.createParallelGroup(Alignment.BASELINE)
						.addComponent(paciente, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(p))
					.addPreferredGap(ComponentPlacement.RELATED)
					.addGroup(gl_consultar.createParallelGroup(Alignment.BASELINE)
						.addComponent(d)
						.addComponent(dentista, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addGap(55))
				.addGroup(gl_consultar.createSequentialGroup()
					.addComponent(consulte, GroupLayout.DEFAULT_SIZE, 64, Short.MAX_VALUE)
					.addGap(48))
		);
		consultar.setLayout(gl_consultar);
		
		//Atualizar(pac);
	}
}
